package com.v2future.sjt.collegecheckingattendance.widget;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by Administrator on 2016/1/22.
 */
public class MyViewPager extends ViewPager {

    private boolean scrollble = true;

    public MyViewPager(Context context) {
        super(context);
    }

    public MyViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**
     * true: viewpager响应滑动事件
     * false: 子View响应滑动事件
     */
    private boolean willIntercept = true;


    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (!scrollble) {
            return true;
        }
        return super.onTouchEvent(ev);
    }


    public boolean isScrollble() {
        return scrollble;
    }

    public void setScrollble(boolean scrollble) {
        this.scrollble = scrollble;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {
        if (willIntercept) {
            //这个地方直接返回true会很卡
            return super.onInterceptTouchEvent(arg0);
        } else {
            return false;
        }

    }

    /**
     * 设置ViewPager是否拦截点击事件
     * 当界面出现左右滑动冲突的时候使用
     *
     * @param value if true, ViewPager拦截点击事件
     *              if false, ViewPager将不能滑动，ViewPager的子View可以获得点击事件
     *              主要受影响的点击事件为横向滑动
     */
    public void setTouchIntercept(boolean value) {
        willIntercept = value;
    }
}
